package com.research.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.enums.BusinessType;
import com.research.domain.entity.ResearchProduct;
import com.research.service.IResearchProductService;
import com.common.utils.poi.ExcelUtil;
import com.common.core.page.TableDataInfo;

/**
 * 研究机构-机构项目、成果、获奖关联Controller
 *
 * @author hst
 * @date 2025-03-25
 */
@RestController
@RequestMapping("/research/product")
public class ResearchProductController extends BaseController
{
    @Autowired
    private IResearchProductService researchProductService;

    /**
     * 查询研究机构-机构项目、成果、获奖关联列表
     */
    @PreAuthorize("@ss.hasPermi('research:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResearchProduct researchProduct)
    {
        startPage();
        List<ResearchProduct> list = researchProductService.selectResearchProductList(researchProduct);
        return getDataTable(list);
    }

    /**
     * 查询研究机构-机构项目、成果、获奖关联列表
     */
    @PreAuthorize("@ss.hasPermi('research:product:list')")
    @GetMapping("/listInverse")
    public TableDataInfo selectResearchProductListInverse(ResearchProduct researchProduct)
    {
        startPage();
        List<ResearchProduct> list = researchProductService.selectResearchProductListInverse(researchProduct);
        return getDataTable(list);
    }

    /**
     * 导出研究机构-机构项目、成果、获奖关联列表
     */
    @PreAuthorize("@ss.hasPermi('research:product:export')")
    @Log(title = "研究机构-机构项目、成果、获奖关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResearchProduct researchProduct)
    {
        List<ResearchProduct> list = researchProductService.selectResearchProductList(researchProduct);
        ExcelUtil<ResearchProduct> util = new ExcelUtil<ResearchProduct>(ResearchProduct.class);
        util.exportExcel(response, list, "研究机构-机构项目、成果、获奖关联数据");
    }

    /**
     * 获取研究机构-机构项目、成果、获奖关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('research:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(researchProductService.selectResearchProductById(id));
    }

    /**
     * 新增研究机构-机构项目、成果、获奖关联
     */
    @PreAuthorize("@ss.hasPermi('research:product:add')")
    @Log(title = "研究机构-机构项目、成果、获奖关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResearchProduct researchProduct)
    {
        return toAjax(researchProductService.insertResearchProduct(researchProduct));
    }

    /**
     * 修改研究机构-机构项目、成果、获奖关联
     */
    @PreAuthorize("@ss.hasPermi('research:product:edit')")
    @Log(title = "研究机构-机构项目、成果、获奖关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResearchProduct researchProduct)
    {
        return toAjax(researchProductService.updateResearchProduct(researchProduct));
    }

    /**
     * 删除研究机构-机构项目、成果、获奖关联
     */
    @PreAuthorize("@ss.hasPermi('research:product:remove')")
    @Log(title = "研究机构-机构项目、成果、获奖关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(researchProductService.deleteResearchProductByIds(ids));
    }
}
